#include "Helpers.h"

using namespace std;

class DigitMLP {
private:
	CvANN_MLP mlp;
	float testinput[1][95];
	float testoutput[1][10];
public:
	DigitMLP(char* filename) {
		int lsza[3] = {95,100,10};
		CvMat lsz = cvMat(1,3,CV_32S,lsza);
		mlp.create(&lsz);
		mlp.load(filename);
	}

	int predict(IplImage* img) {
		//cvThreshold(img, img, 50, 255, CV_THRESH_OTSU);
		for(int k = 0; k < 60; k++) testinput[0][k] = HorizontalLine(img, k);
		for(int k = 0; k < 35; k++) testinput[0][k+60] = VerticalLine(img, k);
		CvMat tnp = cvMat(1,95,CV_32F,testinput);
		CvMat top = cvMat(1,10,CV_32F,testoutput);
		mlp.predict(&tnp, &top);
		float max = top.data.fl[0]; 
		int maxindex = 0;
		for(int i = 1; i < 10; i++) {
			if(top.data.fl[i] > max) {
				max = top.data.fl[i];
				maxindex = i;
			}
		}
		return maxindex;
	}
};